<script setup lang="ts">
import { Icon } from '@iconify/vue';
import type { Article } from '@/api/article/types.ts';

defineProps<{
  articles: Article[]
}>();
</script>

<template>
  <div class="latest-articles box-radius">
    <div class="latest-header">
      <Icon icon="mingcute:time-fill" class="icon" />
      <span class="title">最新文章</span>
    </div>
    <div class="latest-body">
      <router-link
        v-for="article in articles"
        :key="article.id"
        :to="`/detail/${article.slug}?id=${article.id}`"
        class="article-item"
        target="_blank"
      >
        <span class="article-title">{{ article.title }}</span>
        <time class="article-time">{{ article.publishTime }}</time>
      </router-link>
    </div>
  </div>
</template>

<style scoped lang="less">
.latest-articles {
  width: 100%;
  background-color: #ffffff;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  box-sizing: border-box;

  // 头部样式
  .latest-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid #f0f0f0;

    .icon {
      font-size: 18px;
      color: #10b981; // 使用绿色
    }

    .title {
      font-size: 16px;
      font-weight: 500;
      color: #1a1a1a;
      font-family: 'Noto Sans SC', sans-serif;
    }
  }

  // 文章列表样式
  .latest-body {
    font-family: 'LXGW WenKai', sans-serif;;

    .article-item {
      display: flex;
      flex-direction: column;
      gap: 4px;
      padding: 12px;
      text-decoration: none;
      border-radius: 8px;
      transition: all 0.3s ease;

      &:hover {
        background-color: #f8fafc;

        .article-title {
          color: #3b82f6;
        }
      }

      .article-title {
        font-size: 14px;
        color: #334155;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        line-height: 1.5;
        transition: color 0.3s ease;
      }

      .article-time {
        font-size: 12px;
        color: #94a3b8;
      }
    }
  }
}
</style>
